﻿using System;
using System.Collections.Generic;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    struct RefUs
    {
        public override string ToString()
        {
            return string.Join(",", Enumerable.ToList( Enumerable.Select(items, i => i.ToString())).ToArray());
        }
         List<RefU> items ;

        public void Write(BinaryWriter writer)
        {
            ushort count = (ushort) items.Count;
            writer.Write(count);
            foreach (var refU in items)
            {
                refU.Write(writer);
            }
        }

        public void Read(BinaryReader reader)
        {
            ushort count = reader.ReadUInt16();
            items = new List<RefU>();
            for (int i = 0; i < count; i++)
            {
                RefU u = new RefU();
                u.Read(reader);
                items.Add(u);
            }
        }

        public void CreateItems()
        {
            items = new List<RefU>();
        }

        public void AddItem(RefU refU)
        {
            items.Add(refU);
        }

        public RefU this[int i]
        {
            get { return this.items[i]; }
        }
    }
}